<template>
  <div class="app-container search-table-box aidex-table">
    <el-card shadow="never" ref="queryRef" style="margin-bottom: 12px;" class="search_card" v-show="showSearch">
      <div class="filter-container">
        <div class="search_box">
          <el-form :model="queryParams" ref="queryForm" label-width="80px" size="mini">
            <el-row :gutter="16">
              <el-col :md="6" >
                <el-form-item label="税款所属期" prop="period">
                  <el-input
                    v-model="queryParams.period"
                    placeholder="请输入税款所属期"
                    clearable
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
              </el-col>
              <el-col :md="6" >
                <el-form-item label="统计表状态" prop="statStatus">
                  <el-select v-model="queryParams.statStatus" placeholder="请选择统计表状态" @change="handleQuery" clearable filterable  style="width: 100%;">
                    <el-option
                      v-for="dict in dict.type.stat_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :md="6" align="right" style="float: right;">
                <el-form-item>
                  <el-button class="filter-item" type="primary" @click="handleQuery">搜索</el-button>
                  <el-button class="filter-item" style="margin-left: 8px" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
    </el-card>
    <el-card shadow="never" >
      <template #header>
        <el-row>
          <el-col :span="8">
            <div class="card-header">
              <el-button disabled type="text">统计表信息</el-button>
            </div>
          </el-col>
          <el-col :span="16">
            <div class="btn_box" align="right" style="float: right;">
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                type="primary"
                @click="handleCreateApply"
                size="mini"
                :disabled="single"
                v-hasPermi="['doc:deductionstat:createapply']"
              >申请统计</el-button>
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                type="danger"
                @click="handleCancelApply"
                :disabled="single"
                size="mini"
                v-hasPermi="['doc:deductionstat:cancelapply']"
              >申请撤销</el-button>
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                type="primary"
                @click="handleConfirmApply"
                :disabled="single"
                size="mini"
                v-hasPermi="['doc:deductionstat:confirmapply']"
              >确认签名</el-button>
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                type="danger"
                @click="handleConfirmCancelApply"
                :disabled="single"
                size="mini"
                v-hasPermi="['doc:deductionstat:confirmcancelapply']"
              >取消签名</el-button>
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                icon="el-icon-download"
                @click="handleExport"
                size="mini"
                v-hasPermi="['doc:deductionstat:export']"
              >导出</el-button>
              <right-toolbar :showSearch.sync="showSearch" @showSearchFun="showSearchFun" @queryTable="getList"></right-toolbar>
            </div>
          </el-col>
        </el-row>
      </template>

      <el-table
              border
              stripe
              default-expand-all
              ref="tableRef"
              v-loading="loading"
              :data="deductionstatList"
              @selection-change="handleSelectionChange"
              :row-style="rowClass"
              :header-cell-style= "{
                'font-size': '14px !important',
                'font-weight': '500 !important',
                'background-color':'rgb(241 241 241 / 52%)'
              }"
              highlight-current-row style="width: 100%;"
              :height="tableHeight"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="客户公司" align="center" prop="siteName" width="250" show-overflow-tooltip/>
        <el-table-column label="税号" align="center" prop="taxNo"  width="200" show-overflow-tooltip/>
        <el-table-column label="税款所属期" align="center" prop="period"  width="110" />
        <el-table-column label="生成申请结果" align="center" prop="applyResultName" width="150"/>
        <el-table-column label="确认结果" align="center" prop="confirmResultName" width="150"/>
        <el-table-column label="统计表状态" align="center" prop="statStatusName" width="150"/>
        <el-table-column label="处理状态" align="center" prop="statFlowStatusName" width="150"/>
        <el-table-column label="成功标志" align="center" prop="success" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.success" :value="scope.row.success"/>
          </template>
        </el-table-column>
        <el-table-column label="错误码" align="center" prop="code" />
        <el-table-column label="错误信息" align="center" prop="message" />
        <el-table-column label="最近一次申请时间" align="center" prop="lastApplyTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.lastApplyTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="130" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleView(scope.row)"
              v-hasPermi="['doc:deductionstat:edit']"
            >查看</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-dropdown @command="(command) => handleCommand(command, scope.row)"
                         v-hasPermi="['doc:deductionstat:invoicelist', 'doc:deductionstat:sync']">
                    <span class="el-dropdown-link">
                      <el-button type="text">更多</el-button><i class="el-icon-arrow-down el-icon--right"></i>
                    </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="handleSync" v-hasPermi="['doc:deductionstat:sync']">同步结果
                </el-dropdown-item>
                <el-dropdown-item command="handleShowInvoice" v-hasPermi="['doc:deductionstat:invoicelist']">发票列表
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
        <div slot="empty">
          <svg-icon icon-class="search-none" style="font-size: 64px;" />
          <p>暂无数据</p>
        </div>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 查看统计表对话框 -->
      <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1200px" top="10vh" append-to-body>
        <div style="height: 550px;overflow: auto; padding: 12px 24px;">
          <el-form ref="form" size="small" :model="form" label-position="left" label-width="120px">
            <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="客户公司:" prop="siteName">
                  <strong>{{form.siteName}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="税号:" prop="taxNo">
                  <strong>{{form.taxNo}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="税款所属期:" prop="period">
                  <strong>{{form.period}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="统计表状态:" prop="statStatusName">
                  <strong>{{form.statStatusName}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="生成申请结果:" prop="applyResultName">
                  <strong>{{form.applyResultName}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="确认结果:" prop="confirmResultName">
                  <strong>{{form.confirmResultName}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="处理状态:" prop="statFlowStatusName">
                  <strong>{{form.statFlowStatusName}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="是否成功:" prop="success">
                  <strong>{{form.success == 'false' ? '失败' : '成功'}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="错误码:" prop="code">
                  <strong>{{form.code}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="错误信息:" prop="message">
                  <strong>{{form.message}}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="最近同步时间:" prop="lastApplyTime">
                  <strong>{{ parseTime(form.lastApplyTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</strong>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-divider content-position="center">统计明细信息</el-divider>
              </el-col>
              <el-col :span="24">
                <el-table :data="form.tinDeductionStatEntryList" :row-class-name="rowTInDeductionStatEntryIndex" @selection-change="handleTInDeductionStatEntrySelectionChange" style="width: 100%" height="400px" ref="tInDeductionStatEntry">
                  <el-table-column label="发票类型" prop="invoiceTypeName"  width="250" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{scope.row.invoiceTypeName}}
                    </template>
                  </el-table-column>
                  <el-table-column label="抵扣发票份数" prop="invoiceCount" width="150">
                    <template slot-scope="scope">
                      {{scope.row.invoiceCount}}
                    </template>
                  </el-table-column>
                  <el-table-column label="抵扣总金额" prop="invoiceAccount" width="120">
                    <template slot-scope="scope">
                      {{scope.row.invoiceAccount}}
                    </template>
                  </el-table-column>
                  <el-table-column label="抵扣总可抵扣税额" prop="invoiceTaxEffective" width="150">
                    <template slot-scope="scope">
                      {{scope.row.invoiceTaxEffective}}
                    </template>
                  </el-table-column>
                  <el-table-column label="不抵扣发票份数" prop="invoiceCountNondeductible" width="150">
                    <template slot-scope="scope">
                      {{scope.row.invoiceCountNondeductible}}
                    </template>
                  </el-table-column>
                  <el-table-column label="不抵扣总金额" prop="invoiceAccountNondeductible" width="140">
                    <template slot-scope="scope">
                      {{scope.row.invoiceAccountNondeductible}}
                    </template>
                  </el-table-column>
                  <el-table-column label="不抵扣总可抵扣税额" prop="invoiceTaxEffectiveNondeductible" width="180">
                    <template slot-scope="scope">
                      {{scope.row.invoiceTaxEffectiveNondeductible}}
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button  size="mini" @click="cancel">关 闭</el-button>
        </div>
      </el-dialog>

      <!-- 发票列表弹出框 -->
      <el-dialog :close-on-click-modal="false" :title="invoiceTitle" :visible.sync="invoiceOpen" width="1200px" top="10vh" append-to-body>
        <div style="height: 490px;overflow: auto; padding: 12px 24px;">
          <el-table
            border
            stripe
            default-expand-all
            ref="invoiceListTableRef"
            :data="invoiceList"
            :header-cell-style= "{
                'font-size': '14px !important',
                'font-weight': '500 !important',
                'background-color':'rgb(241 241 241 / 52%)'
              }"
            highlight-current-row style="width: 100%;"
            height="450"
          >
            <el-table-column label="发票类型" align="left" key="invoiceTypeName" prop="invoiceTypeName"  width="200"/>
            <el-table-column label="开票日期" align="left" key="invoiceDate" prop="invoiceDate"  width="100">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.invoiceDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="税款所属期" align="left" key="deductiblePeriod" prop="deductiblePeriod"  width="150"/>
            <el-table-column label="发票代码" align="left" key="invoiceCode" prop="invoiceCode" width="120" />
            <el-table-column label="发票号码" align="left" key="invoiceNo" prop="invoiceNo"  width="200"/>
            <el-table-column label="校验码" align="left" key="checkCode" prop="checkCode"  width="150"/>
            <el-table-column label="购方名称" align="left" key="purchaserName" prop="purchaserName"  width="180"/>
            <el-table-column label="购方税号" align="left" key="purchaserTaxNo" prop="purchaserTaxNo"  width="180"/>
            <el-table-column label="销方名称" align="left" key="saleName" prop="saleName"  width="250" show-overflow-tooltip/>
            <el-table-column label="销方税号" align="left" key="saleTaxNo" prop="saleTaxNo"  width="200"/>
            <el-table-column label="用途备注" align="left" key="useRemark" prop="useRemark"  width="150"/>
            <el-table-column label="不含税金额" align="left" key="totalAmount" prop="totalAmount"  width="150"/>
            <el-table-column label="合计税额" align="left" key="totalTax" prop="totalTax"  width="150"/>
            <el-table-column label="价税合计" align="left" key="amountTax" prop="amountTax"  width="150"/>
            <el-table-column label="可抵扣税额" align="left" key="deductTax" prop="deductTax"  width="150"/>
            <el-table-column label="校验状态" align="left" key="verifyStatusName" prop="verifyStatusName"  width="150"/>
            <el-table-column label="发票状态" align="left" key="invoiceStateName" prop="invoiceStateName"  width="150"/>
            <el-table-column label="红蓝发票" align="left" key="isRedName" prop="isRedName"  width="150"/>
            <el-table-column label="认证类型" align="left" key="certificationTypeName" prop="certificationTypeName"  width="150"/>
            <el-table-column label="是否认证" align="left" key="deductibleName" prop="deductibleName"  width="150"/>
            <el-table-column label="发票备注" align="left" key="invoiceRemark" prop="invoiceRemark"  width="150"/>
            <el-table-column label="查验时间" align="left" key="inspectionTime" prop="inspectionTime"  width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.inspectionTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="查验状态" align="left" key="inspectionStatusName" prop="inspectionStatusName"  width="150"/>
            <div slot="empty">
              <svg-icon icon-class="search-none" style="font-size: 64px;" />
              <p>暂无数据</p>
            </div>
          </el-table>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button  size="mini" @click="closeInvoiceOpen">关 闭</el-button>
        </div>
      </el-dialog>

      <!-- 查询条件-${column.columnAlias}-弹出查询 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="查询条件-${column.columnAlias}查询" :visible.sync="searchsiteCodeDialogOpen" width="800px" append-to-body>
        <div class="dialog_box" style="height:550px;">
            <el-form label-position="left" :model="searchsiteCodeQueryParams" :inline="true"  ref="searchsiteCodeQueryForm" label-width="88px" >
                <el-form-item  prop="searchsiteCodeSearchValue">
                    <el-input
                            v-model="searchsiteCodeQueryParams.searchValue"
                            size="mini"
                            placeholder="请输入编码或名称查询${column.columnAlias}"
                            @keyup.enter.native="handleSearchsiteCodeQuery"
                            clearable
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearchsiteCodeQuery">查询</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="searchsiteCodeSelectLoading" :data="searchsiteCodeList"
                      height="400"
                      @row-click="handleSearchsiteCodeRowClick"
                      ref="searchsiteCodeMultipleTable"
                      :row-key="getSearchsiteCodeListRowKey"
                      :row-style="{height:2+'px'}"
                      :header-cell-style= "{
                        'font-size': '14px !important',
                        'font-weight': '500 !important',
                        'background-color':'rgb(241 241 241 / 52%)'
                      }"
                      :cell-style="{padding:'2px 4px'}"
                      border
                      @selection-change="handleSearchsiteCodeSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <!-- 数据 -->
                <el-table-column prop="companycode" label="客户公司代码代码" width="180"></el-table-column>
                <el-table-column prop="companyname" label="客户公司代码名称" ></el-table-column>
                <el-table-column prop="remark" label="备注" width="120"></el-table-column>
            </el-table>
            <pagination
                    v-show="searchsiteCodeTotal>0"
                    :total="searchsiteCodeTotal"
                    :page.sync="searchsiteCodeQueryParams.pageNum"
                    :limit.sync="searchsiteCodeQueryParams.pageSize"
                    @pagination="getSearchsiteCodeList"
            />
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="confirmSearchsiteCode">确 定</el-button>
            <el-button size="mini"   @click="searchsiteCodeCancel">取 消</el-button>
        </div>
    </el-dialog>

      <!-- 编辑-${column.columnAlias}-弹出查询 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="编辑统计表-${column.columnAlias}选择" :visible.sync="siteCodeDialogOpen" width="800px" append-to-body>
        <div class="dialog_box" style="height:550px;">
            <el-form label-position="left" :model="siteCodeQueryParams" :inline="true"  ref="siteCodeQueryForm" label-width="88px" >
                <el-form-item  prop="siteCodeSearchValue">
                    <el-input
                            v-model="siteCodeQueryParams.searchValue"
                            size="mini"
                            placeholder="请输入编码或名称查询${column.columnAlias}"
                            @keyup.enter.native="handlesiteCodeQuery"
                            clearable
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handlesiteCodeQuery">查询</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="siteCodeSelectLoading" :data="siteCodeList"
                      height="400"
                      @row-click="handlesiteCodeRowClick"
                      ref="siteCodeSingleTable"
                      :row-key="getsiteCodeListRowKey"
                      :row-style="{height:2+'px'}"
                      :header-cell-style= "{
                        'font-size': '14px !important',
                        'font-weight': '500 !important',
                        'background-color':'rgb(241 241 241 / 52%)'
                      }"
                      :cell-style="{padding:'2px 4px'}"
                      border
                      @selection-change="handlesiteCodeSelectionChange">
                <el-table-column label="选择" width="60">
            　　　　<template slot-scope="scope">
            　　　　　　<el-radio v-model="siteCodeDialogRadio" :label="scope.row"><i></i></el-radio>
            　　　　</template>
            　　 </el-table-column>
                <!-- 数据 -->
                <el-table-column prop="companycode" label="${column.columnAlias}代码" width="180"></el-table-column>
                <el-table-column prop="companyname" label="${column.columnAlias}名称" ></el-table-column>
                <el-table-column prop="remark" label="备注" width="120"></el-table-column>
            </el-table>
            <pagination
                    v-show="siteCodeTotal>0"
                    :total="siteCodeTotal"
                    :page.sync="siteCodeQueryParams.pageNum"
                    :limit.sync="siteCodeQueryParams.pageSize"
                    @pagination="getsiteCodeList"
            />
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="confirmsiteCode">确 定</el-button>
            <el-button size="mini" @click="siteCodeCancel">取 消</el-button>
        </div>
    </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { listDeductionstat, getDeductionstat, delDeductionstat, addDeductionstat, updateDeductionstat,
    deductionstatCreateApply, deductionstatCancelApply, deductionstatConfirmApply, deductionstatConfirmCancelApply, deductionstatSync } from "@/api/doc/deductionstat";
import { listCompany as listcompany, getCompany as getcompany } from "@/api/core/company";
/* 城市列表 **/
import { provinceList, cityList, districtList } from "@/api/system/city";
import { getInvoiceListByPeriod } from "@/api/doc/ininvoice";


export default {
  name: "Deductionstat",
  dicts: ['stat_flow_status', 'success', 'confirm_result_code', 'stat_status', 'stat_result_code'],
  data() {
    return {
      advanced: false,
      tableHeight: this.getInitTableHeight(),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedTInDeductionStatEntry: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 统计表表格数据
      deductionstatList: [],
      // 抵扣统计明细表格数据
      tInDeductionStatEntryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否弹出发票列表
      invoiceOpen: false,
      // 发票列表
      invoiceList: [],
      // 发票弹出层标题
      invoiceTitle: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params:{

        },
        statId: null,
        custId: null,
        siteCode: null,
        taxNo: null,
        period: null,
        applyResultCode: null,
        confirmResultCode: null,
        statStatus: null,
        statFlowStatus: null,
        success: null,
        code: null,
        message: null,
        lastApplyTime: null,
        resultId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },

      /* ======================================省市区======================================  */
      // 省
      provinceId: null,
      provinceList:[],
      // 市
      cityId: null,
      cityList:[],
      // 区
      districtId: null,
      districtList:[],

      /* ======================================查询条件-客户公司代码选择======================================  */
      searchsiteCodes:[],
      searchsiteCodenames:[],
      searchsiteCodeTotal: 0,
      searchsiteCodeList: [],
      searchsiteCodeDialogOpen: false,
      searchsiteCodeSelectLoading: false,
      searchsiteCodeQueryParams: {
          searchValue: null,
          pageNum: 1,
          pageSize: 20,
      },
      /* ======================================编辑-客户公司代码选择======================================  */
      siteCodename: null,
      siteCodeTotal: 0,
      siteCodeList: [],
      siteCodeDialogRadio: null,
      siteCodeDialogOpen: false,
      siteCodeSelectLoading: false,
      siteCodeQueryParams: {
          searchValue: null,
          pageNum: 1,
          pageSize: 20,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 行样式 */
    rowClass({ row, rowIndex }) {
      if (this.ids.includes(row.id)) {
          return { background: "#d9edf7", height:'20px' };
      } else {
          return { height:'20px'};
      }
    },
   /** 隐藏搜索按钮操作 */
   showSearchFun(isShowSearch){
      this.showSearch = isShowSearch
      let oldHeight = this.$refs.queryRef.$el.offsetHeight
      if(!isShowSearch){
          //当前是显示状态
          oldHeight = oldHeight + 12
      }else{
          oldHeight = oldHeight - 12
      }
      this.$nextTick(() => (
         this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
      ))
    },
    /** 展开按钮操作 */
    toggleAdvanced() {
      const oldHeight = this.$refs.queryRef.$el.offsetHeight
      this.advanced = !this.advanced
      this.$nextTick(() => (
         this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
      ))
    },
    /** 查询统计表列表 */
    getList() {
      this.loading = true;
      listDeductionstat(this.queryParams).then(response => {
        this.deductionstatList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        statId: null,
        custId: null,
        siteCode: null,
        siteName: null,
        taxNo: null,
        period: null,
        applyResultCode: null,
        applyResultName: null,
        confirmResultCode: null,
        confirmResultName: null,
        statStatus: null,
        statStatusName: null,
        statFlowStatus: null,
        statFlowStatusName: null,
        success: null,
        code: null,
        message: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        lastApplyTime: null,
        resultId: null
      };
      this.tInDeductionStatEntryList = [];
      this.resetForm("form");
    },


      /* ※※ 查询 省市区 相关方法 start ※※ */
      // 获取省
      getProvinceList(){
          provinceList().then(response => {
              this.provinceList = response.data;
          });
      },
      // 获取市
      getCityList(){
          console.log(this.provinceId);
          cityList( {"parentId" : this.provinceId } ).then(response => {
              this.cityList = response.data;
          });
      },
      // 获取区县
      getDistrictList(){
          districtList( {"parentId" : this.cityId } ).then(response => {
              this.districtList = response.data;
          });
      },
      // 选中省份
      handleChangeProvince(val){
          // 给表单省字段赋值
          this.form.provinceid = val;
          let province = {};
          province = this.provinceList.find((item)=>{
              return item.id === val;
          });
          this.form.province = province.name;
          // 城市数据清空、区县数据清空;
          this.cityList = [];
          this.districtList = [];
          // 已选市、区数据清空
          this.cityId = null;
          this.districtId = null;
          // 表单城市、区县数据清空
          this.form.cityid = null;
          this.form.city = null;
          this.form.areaid = null;
          this.form.area = null;
          // 获取城市数据
          this.getCityList();
      },
      // 清空省份
      handleClearProvince(){
          // 城市数据清空、区县数据清空;
          this.cityList = [];
          this.districtList = [];
          // 已选市、区数据清空
          this.cityId = null;
          this.districtId = null;
          // 表单城市、区县数据清空
          this.form.cityid = null;
          this.form.city = null;
          this.form.areaid = null;
          this.form.area = null;
      },
      // 选中城市
      handleChangeCity(val){
          // 给表单市字段赋值
          this.form.cityid = val;
          let city = {};
          city = this.cityList.find((item)=>{
              return item.id === val;
          });
          this.form.city = city.name;
          // 区县数据清空
          this.districtList = [];
          // 已选区县清空
          this.districtId = null;
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
          // 获取城市数据
          this.getDistrictList();
      },
      // 清空省份
      handleClearCity(){
          // 区县数据清空
          this.districtList = [];
          // 已选区县清空
          this.districtId = null;
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
      },
      // 选中区县
      handleChangeDistrict(val){
          // 给表单省字段赋值
          this.form.areaid = val;
          let district = {};
          district = this.districtList.find((item)=>{
              return item.id === val;
          });
          this.form.area = district.name;
      },
      // 清空省份
      handleClearDistrict(){
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
      },

      /* ※※ 查询 省市区 相关方法 end ※※ */


    /* ※※ 查询 客户公司代码 相关方法 start ※※ */
    /** ① 弹出查询条件-客户公司代码 */
    openSearchsiteCodeDialogOpen(){
        this.searchsiteCodeDialogOpen = true;
        // 默认不查询
    },
    /** ② 单击行 **/
    handleSearchsiteCodeRowClick(row, column, event){
        this.$refs.searchsiteCodeSingleTable.toggleRowSelection(row);
    },
    /** ③ 行KEY **/
    getSearchsiteCodeListRowKey(row) {
        return row.companycode
    },
    /** ④ 选中客户公司代码 **/
    handleSearchsiteCodeSelectionChange(selection) {
        this.searchsiteCodes = selection.map(item => item.siteCode);
        this.searchsiteCodenames = selection.map(item => item.companyname);
    },
    /** ⑤ 点击查询按钮 **/
    handleSearchsiteCodeQuery(){
        this.searchsiteCodeQueryParams.pageNum = 1;
        this.getSearchsiteCodeList();
    },
    /** ⑥ 查询 **/
    getSearchsiteCodeList(){
        this.searchsiteCodeSelectLoading = true;
        listcompany(this.searchsiteCodeQueryParams).then(response => {
            this.searchsiteCodeList = response.rows;
            this.searchsiteCodeTotal = response.total;
            this.searchsiteCodeSelectLoading = false;
        });
    },
    /** ⑦ 点击确认查询 **/
    confirmSearchsiteCode() {
        if(this.searchsiteCodes.length > 0){
            this.queryParams.params.siteCodes = this.searchsiteCodes.join(',');
            this.queryParams.params.companynames = this.searchsiteCodenames.join(',');
        }
        // 关闭查询弹出框
        this.searchsiteCodeCancel();
    },
    /** ⑧ 点击关闭查询弹出框 **/
    searchsiteCodeCancel() {
        this.searchsiteCodeDialogOpen = false;
    },
    /* ※※ 查询 客户公司代码 相关方法 end ※※ */


    /* ※※ 编辑 客户公司代码 相关方法 start ※※ */
    /** ① 弹出编辑内容-客户公司代码 */
    opensiteCodeDialogOpen(){
        this.siteCodeDialogOpen = true;
        this.getsiteCodeList();
    },
    /** ② 单击行 **/
    handlesiteCodeRowClick(row, column, event){
        this.$refs.siteCodeSingleTable.toggleRowSelection(row);
    },
    /** ③ 行KEY **/
    getsiteCodeListRowKey(row) {
        return row.companycode
    },
    /** ④ 选中客户公司代码 **/
    handlesiteCodeSelectionChange(selection) {
        if (selection[0]) {
            this.siteCodeDialogRadio = selection[0]
            this.form.companycode = selection[0].companycode;
            this.form.companyname = selection[0].companyname;
        }
    },
    /** ⑤ 点击查询按钮 **/
    handlesiteCodeQuery(){
        this.siteCodeQueryParams.pageNum = 1;
        this.getsiteCodeList();
    },
    /** ⑥ 查询 **/
    getsiteCodeList(){
        this.siteCodeSelectLoading = true;
        listcompany(this.siteCodeQueryParams).then(response => {
            this.siteCodeList = response.rows;
            this.siteCodeTotal = response.total;
            this.siteCodeSelectLoading = false;
        });
    },
    /** ⑦ 点击确认查询 **/
    confirmsiteCode() {
        this.siteCodeCancel();
    },
    /** ⑧ 点击关闭查询弹出框 **/
    siteCodeCancel() {
        this.siteCodeDialogOpen = false;
    },
    /* ※※ 编辑 客户公司代码 相关方法 end ※※ */


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加统计表";
    },

    /** 生成申请按钮操作 */
    handleCreateApply() {
      const ids = this.ids;
      if(ids.length == 0){
          this.$modal.msgError("请先选择要操作的统计表");
          return;
      }
      const id = ids[0];
      this.$modal.confirm('是否确认生成统计表？').then(function() {
          return deductionstatCreateApply(id);
      }).then(() => {
          this.$modal.msgSuccess("操作成功，半小时后同步操作结果");
      }).catch(() => {});
    },

    /** 生成撤销申请按钮操作 */
    handleCancelApply() {
      const ids = this.ids;
      if(ids.length == 0){
          this.$modal.msgError("请先选择要操作的统计表");
          return;
      }
      const id = ids[0];
      this.$modal.confirm('是否确认申请统计表？').then(function() {
          return deductionstatCancelApply(id);
      }).then(() => {
          this.$modal.msgSuccess("操作成功，半小时后同步操作结果");
      }).catch(() => {});
    },

    /** 确认申请按钮操作 */
    handleConfirmApply() {
      const ids = this.ids;
      if(ids.length == 0){
          this.$modal.msgError("请先选择要操作的统计表");
          return;
      }
      const id = ids[0];
      this.$modal.confirm('是否确认统计表签名？').then(function() {
          return deductionstatConfirmApply(id);
      }).then(() => {
          this.$modal.msgSuccess("操作成功，半小时后同步操作结果");
      }).catch(() => {});
    },

    /** 确认取消申请按钮操作 */
    handleConfirmCancelApply() {
      const ids = this.ids;
      if(ids.length == 0){
          this.$modal.msgError("请先选择要操作的统计表");
          return;
      }
      const id = ids[0];
      this.$modal.confirm('是否取消统计表签名？').then(function() {
          return deductionstatConfirmCancelApply(id);
      }).then(() => {
          this.$modal.msgSuccess("操作成功，半小时后同步操作结果");
      }).catch(() => {});
    },

    // 更多操作触发
    handleCommand(command, row) {
        switch (command) {
            case "handleSync":
                this.handleSync(row);
                break;
            case "handleShowInvoice":
                this.handleShowInvoice(row);
                break;
            default:
                break;
        }
    },

    /** 同步按钮操作 */
    handleSync(row) {
        this.reset();
        const id = row.id || this.ids
        deductionstatSync(id).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.getList();
        });
    },

    /** 查看统计表发票按钮操作 */
    handleShowInvoice(row) {
        const period = row.period;
        this.$modal.loading("正在上传图片，请稍候...");
        getInvoiceListByPeriod(period).then(response => {
            this.$modal.closeLoading()
            this.invoiceOpen = true;
            this.invoiceList = response.data;
            this.invoiceTitle = "【" + period + "】税款所属期发票列表"
        });
    },

    closeInvoiceOpen(){
        this.invoiceOpen = false;
        this.invoiceList = [];
        this.invoiceTitle = "";
    },

    /** 查看按钮操作 */
    handleView(row) {
        this.reset();
        const id = row.id || this.ids
        getDeductionstat(id).then(response => {
            this.form = response.data;
            this.open = true;
            this.title = "统计表明细";
        });
    },

    /** 抵扣统计明细序号 */
    rowTInDeductionStatEntryIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 复选框选中数据 */
    handleTInDeductionStatEntrySelectionChange(selection) {
      this.checkedTInDeductionStatEntry = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('doc/deductionstat/export', {
        ...this.queryParams
      }, `deductionstat_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
